

<#include "/base/common/head.html"/>
    
    <table id="dg"></table>
    <div id="tb" style="padding:2px 5px;">
        <div class="wrap_search">
		        		
        </div>
        <div style="text-align: left; margin:6px;">
        	<!--  
            <a href="javascript:void(0)" class="easyui-linkbutton exportBtn" iconCls="glyphicon-export" plain="true" onclick="exportExcel('all')">导出</a>
            -->
            <a href="javascript:void(0)" class="easyui-linkbutton addBtn" iconCls="glyphicon-plus" plain="true" onclick="add('menu')">增加菜单</a>
	        <a href="javascript:void(0)" class="easyui-linkbutton addBtn" iconCls="glyphicon-unchecked" plain="true" onclick="add('button')">增加按钮</a>
            <a href="javascript:void(0)" class="easyui-linkbutton updateBtn" iconCls="glyphicon-pencil" plain="true" onclick="update()">编辑</a>
            <a href="javascript:void(0)" class="easyui-linkbutton delBtn" iconCls="glyphicon-remove" plain="true" onclick="del()">删除</a>
            <a href="javascript:void(0)" class="easyui-linkbutton detailBtn" iconCls="glyphicon-map-marker" plain="true" onclick="detail()">详情</a>
            
          	
            <div id="searchBtnWrap" style="float:right; padding-right:40px;">
                <a href="javascript:void(0)" class="easyui-linkbutton color1" iconCls="glyphicon-search" onclick="zcurdSearch()">搜索</a>
                <a href="javascript:void(0)" class="easyui-linkbutton color2" iconCls="glyphicon-repeat" onclick="flushPage()">重置</a>
            </div>
            
        </div>
    </div>
    
<script type="text/javascript">

//数据表格初始化参数
var dgOptions = {
		idField:"id",
		treeField:"name",
        rownumbers:true, //显示行号
    	fit:true, //自适应父容器
    	border:false, //是否显示面板边框。
    	url:'findAll',  //数据请求URL
    	method:'post', //请求方式
    	toolbar:'#tb', //工具栏
    	//pageSize: 20, //每页数量
    	//pagination:true, //显示分页
    	//fitColumns:true, //自动调整各列宽度。当为true时，各列的宽度值只是一个比例。
    	striped:true, //是否显示斑马线
    	multiSort:false, //是否允许多列排序
		sortName:'orderNum', //初始排序字段
		sortOrder:'asc', //初始排序方式
    	singleSelect: true, //是否单选
		ctrlSelect : true, //启用多选时，允许使用Ctrl键+鼠标进行多选
		showFooter : true, //是否显示行脚
        queryParams: zcurdGetParam(), //请求参数
        onDblClickRow:function(row){dbClickShow(row.id);}, //双击行事件
        columns: [[
		         {field:'id', checkbox:true}
	           	 	,{field:'systemNo', title: '系统编号', width:80, align:'center'   }
	           	 	,{field:'name', title: '名称', width:180, align:'left'   }
	           	 	,{field:'resourceType', title: '类型', width:60, align:'center'  ,formatter:formatType }
	           	 	,{field:'authCode', title: '权限码', width:180, align:'left'   }
	           	 	,{field:'url', title: 'URL', width:330, align:'left'   }
	           	 	,{field:'iconCls', title: '图标', width:180, align:'left'   }
	           	 	,{field:'enabled', title: '是否启用', width:60, align:'center'  ,formatter:formatBoolean1 }
	           	 	,{field:'locked', title: '是否锁定', width:60, align:'center'  ,formatter:formatBoolean1 }
	           	 	,{field:'menuState', title: '状态', width:60, align:'center' }
	           	 	,{field:'orderNum', title: '排序号', width:60, align:'center'   }
	           	 
	           ]],
	      loadFilter: function(data) {
	    	  		return data;
	           }           
	};

var datagrid = $("#dg"); //数据表格

$(function() {
	datagrid.treegrid(dgOptions); //绘制数据表格
	autoAddClear(); //为各组件自动填加‘清除’功能（组件需要增加 addClear属性 ）
});

//查询
function zcurdSearch() {
	var param = zcurdGetParam();
	datagrid.datagrid("load", param)
}

//获取查询参数
function zcurdGetParam() {
	var param = {};
	$("#tb :input[name]").each(function(i, item) {
		if($(item).val()) {
			param[$(item).attr("name")] = $(item).val();	
		}
	});
	//console.log(param);
	return param;
}

var initPara = zcurdGetParam(); //初始化参数，主要目的是保存一些隐藏条件

//增加
function add(addType) {
	top.window.subPage.loadCurrDatagrid = function() { //设置成功后的回调方法
		datagrid.treegrid("load");
	}
	var id ="";
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length >= 1) {
		id = rowsSel[0].id;
		
		//不能给按钮增加下级
		if(rowsSel[0].resourceType.code=='02')
		{
			showWarnMsg("请选择【菜单】");
			return;
		}
			
	}
	if(addType=='menu')
	{
		top.openWindow("增加菜单", getCurrUrl("addPage") + "?fatherId=" + id , {size: '820x360'});
	}
	else
	{
		top.openWindow("增加按钮", getCurrUrl("addButtonPage") + "?fatherId=" + id , {size: '480x362'});
	}
		
}

//修改
function update() {
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请选择需要编辑的一条数据");
		return;
	}
	var id = rowsSel[0].id;
	top.window.subPage.loadCurrDatagrid = function() {
		datagrid.treegrid("reload");
	}
	
	if(rowsSel[0].resourceType.code=='01')
	{//菜单
		top.openWindow("编辑菜单", getCurrUrl("updatePage") + "?id=" + id, {size: '820x360'});
	}
	else
	{//按钮
		top.openWindow("编辑按钮", getCurrUrl("updateButtonPage") + "?id=" + id, {size: '480x362'});
	}	
	
}

//详情
function detail() {
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请选择需要查看的一条数据");
		return;
	}
	var id = rowsSel[0].id;
	dbClickShow(id);
}

//双击打开查看
function dbClickShow(id) {
	top.openWindow_view("详情", getCurrUrl("detailPage") + "?id=" + id, {size: '720x300'});
}

//删除
function del() {
	var locked = false;
	var ids = [];
	$.each(datagrid.datagrid("getSelections"), function(i, item) {
		ids.push(item.id);
		if(item.locked)
		{
			locked = true;
		}
	});
	
	if(ids.length < 1) {
		showWarnMsg("请选择需要删除的数据");
		return;
	}
	if(locked)
	{
		showWarnMsg("已锁定，不允许删除！！！");
		return;
	}
	
	confirmMsg("确认删除?", function() {
		$.post(getCurrUrl("delete"), {ids: ids.join(",")}, function(data) {
			
			if("01" == data.code){//成功
				datagrid.treegrid("reload");
				showMsg(data.msg); //显示消息
			}else if("04" == data.code){//失败
				showErrorMsg(data.msg); //显示错误消息
			}
			
		});
	});
}

//导出Excel
function exportExcel(type) {
	var option = datagrid.datagrid("options");
	var param = option.queryParams;
	param.sort = option.sortName;
	param.order = option.sortOrder;
	param.type = type;
	window.location.href = "exportExcel?" + $.param(param);
}


/**
 * 格式化函数
 */
 
	
//所属菜单 格式化 
function formatfather(value)
{
	if(value == null)
	{
		return "";
	}
	return value.name;
};	


//类型格式化
function formatType(value)
{
	if(value == null)
	{
		return "";
	}
	if(value.code == "02")
	{
		return "<span style='color:#0000ff'>"+value.name+"</span>";
	}
	return value.name;
};

//Boolean 是否
function formatBoolean1(value)
{
	if(value == null)
	{
		return "";
	}
	if(value)
	{
		return "是";
	}
	return "<span style='color:#ff0000'>否</span>";
};

//Boolean 开关
function formatBoolean2(value)
{
	if(value == null)
	{
		return "";
	}
	
	if(value)
	{
		return "开";
	}
	return "关";
};

//类型格式化，不同类型采用不同颜色（参考用）
function formatTypeColor(value)
{
	if(value == null)
	{
		return "";
	}
	if(value.code=='01')
	{
		return "<span style='color:#008B00'>"+value.name+"</span>";
	}
	else if(value.code=='02')
	{
		return "<span style='color:#ff0000'>"+value.name+"</span>";
	}
	else if(value.code=='03')
	{
		return "<span style='color:#20B2AA'>"+value.name+"</span>";
	}
	else if(value.code=='05')
	{
		return "<span style='color:#CDCDB4'>"+value.name+"</span>";
	}
	else if(value.code=='06')
	{
		return "<span style='color:#EEB422'>"+value.name+"</span>";
	}
	return value.name;
};

</script>

<#include "/base/common/dialogWindow.html"/>
<#include "/base/common/foot.html"/>
